<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport"
        content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="../css/aui.2.0.css" />
</head>

<body>
    <header class="aui-bar aui-bar-nav" style="background-color: #03a9f4;position:fixed;" id="header">
        <a class="aui-pull-left aui-btn" tapmode onclick="closeWin();">
            <span class="aui-iconfont aui-icon-left"></span>
        </a>
        <div class="aui-title" id="title">
        </div>
    </header>
    <div class="aui-content aui-margin-b-15" style="margin-top:50px;">
        <ul class="aui-list aui-form-list">
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">检测模板</div>
                    <div class="aui-list-item-input">
                        <input type="text" placeholder="选择检测模板" id="chkTemplateCode" readonly="true"
                            onclick="goSelectChkTemplate()" />
                    </div>
                    <i class="aui-input-addon aui-iconfont aui-icon-right" onclick="goSelectChkTemplate()"></i>
                </div>
            </li>
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">模板名称</div>
                    <div class="aui-list-item-input">
                        <input type="text" id="chkTemplateName" disabled="true">
                    </div>
                </div>
            </li>
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">检测类型</div>
                    <div class="aui-list-item-input">
                        <input type="text" id="chkTypeName" disabled="true">
                    </div>
                </div>
            </li>
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">设备编码</div>
                    <div class="aui-list-item-input">
                        <input type="text" id="equipCode" disabled="true">
                    </div>
                </div>
            </li>
        </ul>
        <p></p>
        <p></p>
        <div class="aui-btn aui-btn-info aui-btn-block" onclick="save()">保存</div>
        <div style="background-color:white; height: 260px;width: 100%;margin-top:3%;border:solid 1px #D3D3D3;display:none"
            id="tableDiv">
            <table class="table" style='width:100%; font-size:14px;' id="table">
                <tbody>
                    <tr>
                        <td style="width:23%;text-align:right;">检&nbsp&nbsp测&nbsp单&nbsp号:</td>
                        <td id="chkBillCodeT"></td>
                    </tr>
                    <tr>
                        <td style="width:23%;text-align:right;">计&nbsp&nbsp划&nbsp日&nbsp期:</td>
                        <td id="billDateT"></td>
                    </tr>
                    <tr>
                        <td style="width:23%;text-align:right;">检&nbsp&nbsp测&nbsp类&nbsp型:</td>
                        <td id="chkTypeNameT"></td>
                    </tr>
                    <tr>
                        <td style="width:23%;text-align:right;">设&nbsp&nbsp备&nbsp编&nbsp码:</td>
                        <td id="equipCodeT"></td>
                    </tr>
                    <tr>
                        <td style="width:23%;text-align:right;">操&nbsp&nbsp&nbsp&nbsp作&nbsp&nbsp&nbsp&nbsp者:</td>
                        <td id="createIdT"></td>
                    </tr>
                    <tr>
                        <td style="width:23%;text-align:right;">操&nbsp&nbsp作&nbsp时&nbsp间:</td>
                        <td id="createDateT"></td>
                    </tr>
                    <tr>
                        <td style="width:23%;text-align:right;">
                            <div class='aui-btn aui-btn-info' onclick='deal()'>处理</div>
                        </td>
                        <td></td>
                    </tr>
                </tbody>
            </table>
        </div>
    </div>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="../script/public.js"></script>
<script type="text/javascript">
    var chkBillType = ""; //检测单类型
    var title = "";

    //初始化查询仓库下拉框
    apiready = function () {
        title = api.pageParam.title;
        chkBillType = api.pageParam.chkBillType;
        document.getElementById("title").innerHTML = title + "创建";

    }

    //选择检测模板
    function goSelectChkTemplate() {

        api.openWin({
            name: 'qcmSelectChkTemplate5s',
            url: 'qcmSelectChkTemplate5s.html',
            pageParam: {
                name: "qcmChkBillCreateEm",
                chkBillType: chkBillType,
            }
        });
    }

    //检测模板选择后回调函数
    function setChkTemplate(code, name, chkTypeName, equipCode) {
        $("#chkTemplateCode").val(code);
        $("#chkTemplateName").val(name);
        $("#chkTypeName").val(chkTypeName);
        $("#equipCode").val(equipCode);
    }

    //保存按钮
    function save() {
        //检测模板编码
        var chkTemplateCode = $("#chkTemplateCode").val();
        //设备编码
        var equipCode = $("#equipCode").val();

        //检测模板非空校验
        if (chkTemplateCode == "" || chkTemplateCode == null || chkTemplateCode == undefined) {
            api.toast({
                msg: '请选择检测模板',
                duration: 3000
            });
            return;
        }

        //设备编码非空校验
        if (equipCode == "" || equipCode == null || equipCode == undefined) {
            api.toast({
                msg: '设备编码不能为空',
                duration: 3000
            });
            return;
        }

        api.showProgress({
            title: '保存中...',
        });
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/qcmChkBillCreateSave5s";
        var data = {
            values: {
                chkBillType: chkBillType, //检测单类型
                chkTemplateCode: chkTemplateCode, //检测模板编码
                un: un
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                //成功
                if (myobj.code == 'S') {

                    api.hideProgress();
                    api.toast({
                        msg: "保存成功",
                        duration: 3000
                    });

                    //清空表单
                    $("#chkTemplateCode").val("");
                    $("#chkTemplateName").val("");
                    $("#chkTypeName").val("");
                    $("#equipCode").val("");

                    var map = myobj.data;
                    for (var key in map) {
                        $("#" + key).html(map[key]);
                    }
                    $("#tableDiv").css('display', 'block');

                } else {
                    api.hideProgress();
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            } else {
                api.hideProgress();
            }
        });
    }

    //检测单处理
    function deal() {
        //检测单号
        var chkBillCode = $("#chkBillCodeT").html();
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getChkBill";
        var data = {
            values: {
                chkBillType: chkBillType,
                chkBillCode: chkBillCode,
                un: un,
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                if (myobj.code == '0') {
                    var list = eval(myobj.list);

                    openDeal(list[0].sysid, list[0].code);
                } else {
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            }
        });
    }

    //处理
    function openDeal(chkBillId, chkBillCode) {
        api.openWin({
            name: 'qcmChkBillDeal5s',
            url: 'qcmChkBillDeal5s.html',
            pageParam: {
                chkBillId: chkBillId,
                chkBillCode: chkBillCode,
                name: "qcmChkBillCreateEm",
                title: title + "处理",
            }
        });
    }

    function doSearch() {
        var chkBillCode = $("#chkBillCodeT").html();
        api.toast({
            msg: "检测单号【" + chkBillCode + "】已处理！",
            duration: 3000
        });

        $("#tableDiv").css('display', 'none');
    }

    //返回按钮
    function closeWin() {
        api.closeWin({});
    }
</script>

</html>